<?php

namespace WoXuanWang\Advertisement\Models;

use Eloquent as Model;

/**
 * Class Advertisement
 * @package WoXuanWang\Advertisement\Models
 * @version April 6, 2017, 6:47 pm CST
 */
class Advertisement extends Model
{

    public $table = 'advertisements';
    


    public $fillable = [
        'ad_slot_id',
        'url',
        'image_upload_id',
        'description',
        'start_at',
        'end_at'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'ad_slot_id' => 'integer',
        'url' => 'string',
        'image_upload_id' => 'integer',
        'description' => 'string',
        'start_at' => 'date',
        'end_at' => 'date'
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'url' => 'required'
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     **/
    public function adSlot()
    {
        return $this->belongsTo(\WoXuanWang\Advertisement\Models\AdSlot::class, 'ad_slot_id', 'id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function upload()
    {
        return $this->hasOne(\WoXuanWang\Advertisement\Models\Upload::class, 'image_upload_id', 'id');
    }
}
